 % Copyright (C) 2012 	Paul Bovbel, paul@bovbel.com
 % 						Richard Abrich, abrichr@gmail.com
 %
 % This file is part our empirical study of boosting algorithms (http://code.google.com/p/boosting-study/)
 % 
 % This is free software; you can redistribute it and/or modify
 % it under the terms of the GNU General Public License as published by
 % the Free Software Foundation; either version 3 of the License, or
 % (at your option) any later version.
 % 
 % This source code is distributed in the hope that it will be useful,
 % but WITHOUT ANY WARRANTY; without even the implied warranty of
 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 % GNU General Public License for more details.
 % 
 % You should have received a copy of the GNU General Public License
 % along with this source code. If not, see http://www.gnu.org/licenses/

function [ data ] = expand_cats( orig_data )
%   Pre-process data for perceptron function
%   Continuous features can be used directly, but a categorical feature (1
%   of x) need to be remapped to individual binary features x * (1 of 2)

%number of features in data
N_dims = size(orig_data,2) - 1;

%directly map classes
data = orig_data(:,1);

%map features
for n=2:N_dims+1
    
    map = orig_data(:,n); %data to be remapped
    
    %check if integer (categorical), then need to remap categories to binary features  
    if isequal(fix(map),map)                   
        num_cats = max(map);    %get number of categories in feature
        
        for j=1:num_cats        %cycle through each category
            remap = map == j;   %convert to binary feature
            data = [data remap];
            
        end
         
    %otherwise continuous feature, map normalized
    else                        
        data = [data map/max(map)];    
    end
     
end

